﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gfPage;
using gfLibrary;
using DBUtility;
using Model;
using BLL;

namespace IYAKASAPortal
{
    public partial class DEV_INFO_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             gfAjaxJs.SetNoCache();

             if (Page.IsPostBack == false)
             {
                 btnSearch_Click(sender, e);
             }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;

            string strSql = "select * from DEV_INFO";

            if (strKeywords.Length > 0)
            {
                strSql += " where ";
                strSql += "ID like '%" + strKeywords + "%'";
                strSql += " or JCXH like '%" + strKeywords + "%'";
                strSql += " or SBRZBH like '%" + strKeywords + "%'";
                strSql += " or CGJXH like '%" + strKeywords + "%'";
                strSql += " or CGJSCC like '%" + strKeywords + "%'";
                strSql += " or CGJCCBH like '%" + strKeywords + "%'";
                strSql += " or FQYXH like '%" + strKeywords + "%'";
                strSql += " or FQYSCC like '%" + strKeywords + "%'";
                strSql += " or FQYCCBH like '%" + strKeywords + "%'";
                strSql += " or LLJXH like '%" + strKeywords + "%'";
                strSql += " or LLJSCC like '%" + strKeywords + "%'";
                strSql += " or LLJCCBH like '%" + strKeywords + "%'";
                strSql += " or YDJXH like '%" + strKeywords + "%'";
                strSql += " or YDJSCC like '%" + strKeywords + "%'";
                strSql += " or YDJCCBH like '%" + strKeywords + "%'";

            }

            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, Config.AppConfig.g_strConnectionStringSqlClient, strSql, 20);

            rptList.DataSource = m_dtTable;
            rptList.DataBind();

            m_dtTable.Dispose();
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;
            btnSearch_Click(sender, null);
         }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnBrowse_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if((strUniqueKey == null)||(strUniqueKey.Length == 0)||(gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("DEV_INFO_Insert_Update.aspx?m=b&UniqueKey=" + strUniqueKey);
        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
            Response.Redirect("DEV_INFO_Insert_Update.aspx?m=i");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if((strUniqueKey == null)||(strUniqueKey.Length == 0)||(gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("DEV_INFO_Insert_Update.aspx?m=u&UniqueKey=" + strUniqueKey);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

            string strUniqueKey = Request.Form["txtUniqueKey"];

            if((strUniqueKey == null)||(strUniqueKey.Length == 0)||(gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            DEV_INFO_BLL m_DEV_INFO_BLL =new DEV_INFO_BLL();

            if(m_DEV_INFO_BLL.Exists(Convert.ToInt32(strUniqueKey)) == true)
            {
                if(m_DEV_INFO_BLL.Delete(Convert.ToInt32(strUniqueKey)) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "删除成功！");
                    btnSearch_Click(sender, e);
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "删除失败！");
                }
            }
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];
            Response.Redirect("equip_type_Insert_Update.aspx?m=u&UniqueKey=" + strUniqueKey);
        }
    }
}
